# controller.py

from PySide6.QtWidgets import QApplication
from model import TimeModel
from view import MainWindow, TimeWindow

class Controller:
    def __init__(self):
        self.model = TimeModel()
        self.main_window = MainWindow(self)
        self.time_window = None

    def show_main_window(self):
        self.main_window.show()

    def show_time_window(self, event):
        if not self.time_window:
            self.time_window = TimeWindow(self)
            self.model.start()
        self.time_window.show()
        self.time_window.raise_()

    def toggle_time_display(self):
        if self.model.running:
            self.model.stop()
            self.time_window.pause_button.setText("开始")
        else:
            self.model.start()
            self.time_window.pause_button.setText("暂停")

        self.update_time_label()

    def update_time_label(self):
        self.time_window.time_label.setText(self.model.get_current_time())